import QtQuick 2.0

Item {
	property var item
	property bool allowFetch: true
	signal itemSelected(var data);

	id: root

	Loader {
		id: loader
		width: parent.width
		height: parent.height
		Component.onCompleted: {
			var item = root.item;
			if(item.items) {
				loader.setSource("CollectionView.qml", {item: item});
			}
			else if(item.body) {
				loader.setSource("ContentView.qml", {item: item});
			}
			else if(allowFetch) {
				loader.setSource("ItemLoaderView.qml", {item: item});
			}
			else {
				loader.setSource("ErrorView.qml", {error: "Unable to render item."});
			}
		}
	}
	Connections {
		target: loader.item
		onItemSelected: {
			itemSelected(data)
		}
	}
}
